/**
 * @Description： Remark接口的实现
 * @author： 20155872 游宇
 * @createTime: 2018-05-10 10:28
 **/
package com.campus_information_portal.service.impl;

import com.campus_information_portal.dao.RemarkDao;
import com.campus_information_portal.entity.Remark;
import com.campus_information_portal.service.RemarkService;
import com.campus_information_portal.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @className: RemarkImpl
 * @Description: Remark接口的实现
 * @author: 20155872 游宇
 * @createTime: 2018-05-10 10:28
 **/
@Service
public class RemarkImpl implements RemarkService {
    @Autowired
    private RemarkDao remarkDao;

    /**
     * @Description: 根据学期和学生id 来查询某学生某学期的评教记录
     * @author: 20155872 游宇
     * @methodName: searchRemarks
     * @param:  int stu_info_id, int term_id
     * @returnType: List<Remark>
     * @createTime: 2018/5/14 18:07
     **/
    @Override
    public Msg searchRemarks(int stu_info_id, int term_id) {
        List<Remark> remarkList=remarkDao.searchRemarks(stu_info_id,term_id);
        if (remarkList.size()!=0){
           return Msg.addData(1,"根据学生信息id和学期id查询评价记录成功！",remarkList);
        }

        return Msg.fail();
    }

    /**
     * @Description: 插入一条评价记录
     * @author: 20155872 游宇
     * @methodName: addremark
     * @param: Remark remark
     * @returnType: boolean
     * @createTime: 2018/5/14 18:07
     **/
    @Override
    public Msg addRemark(Remark remark) {
        if (remarkDao.addRemark(remark)){
            return Msg.addData(1,"添加一条评价记录成功！");
        }
        return Msg.fail();
    }
    /**
     * @Description: 根据remarkid来获取remark记录
     * @author: 20155872 游宇
     * @methodName: updateRemark
     * @param: Remark remark
     * @returnType: boolean
     * @createTime: 2018/5/15 16:21
     **/
    @Override
    public Msg updateRemark(Remark remark) {
        if (remarkDao.updateRemark(remark)){
            return Msg.addData(1,"更新一条评价记录成功！");
        }
        return Msg.fail();
    }

    /**
     * @Description: 根据remarkId 删除一条remark记录
     * @author: 20155872 游宇
     * @methodName: deleteByRemarkId
     * @param: int remarkId
     * @returnType: Msg
     * @createTime: 2018/5/15 16:55
     **/
    @Override
    public Msg deleteByRemarkId(int remarkId) {
        if (remarkDao.deleteByRemarkId(remarkId)){
            return Msg.addData(1,"成功根据remark记录id删除一条评价记录！");
        }
        return Msg.fail();
    }

    @Override
    public Msg getAllMarkNineByteInfoIdAndterm(int teInfoId, int termId) {
         List<String> stringList=remarkDao.getAllMarkNineByteInfoIdAndterm(teInfoId,termId);
         if (stringList.size()!=0){
             return Msg.addData(1,"已成功查询该学期该教师问题9 的所有建议",stringList);
         }
         return Msg.fail();
    }

    @Override
    public Msg getAllMarkTenByteInfoIdAndterm(int teInfoId, int termId) {
        List<String> stringList=remarkDao.getAllMarkTenByteInfoIdAndterm(teInfoId,termId);
        if (stringList.size()!=0){
            return Msg.addData(1,"已成功查询该学期该教师问题10 的所有建议",stringList);
        }
        return Msg.fail();
    }

    @Override
    public Msg getAvgGrade(int termId, int teInfoId) {
        BigDecimal bigDecimal=remarkDao.getAvgGrade(termId,teInfoId);
        if (bigDecimal!=null){
            return Msg.addData(1,"成功！",bigDecimal);
        }
        return Msg.fail();
    }


}
